import provinceAndCity from "@/utils/province.json";


export default function translateAddress(value) {
  let province = "";
  let city = "";
  let district = "";
  for (var k = 0, lengthk = provinceAndCity.length; k < lengthk; k++) {
    //确定省
    if (provinceAndCity[k].code == value[0]) {
      province = provinceAndCity[k].name;
      if (
        provinceAndCity[k].cityList &&
        value.length >= 2 &&
        value[1] != ""
      ) {
        for (
          var i = 0, lengthi = provinceAndCity[k].cityList.length;
          i < lengthi;
          i++
        ) {
          //确定市
          if (
            provinceAndCity[k].cityList[i].code == value[1] ||
            provinceAndCity[k].cityList.length == 1
          ) {
            city = provinceAndCity[k].cityList[i].name;
            //确定区
            if (
              provinceAndCity[k].cityList[i].areaList &&
              value.length == 3 &&
              value[2] != ""
            ) {
              for (
                var j = 0,
                  lengthj = provinceAndCity[k].cityList[i].areaList.length;
                j < lengthj;
                j++
              ) {
                if (
                  provinceAndCity[k].cityList[i].areaList[j].code ==
                  value[2]
                ) {
                  district =
                    provinceAndCity[k].cityList[i].areaList[j].name;
                  break;
                }
              }
            }
            break;
          }
        }
      }
      break;
    }
  }
  return [province, city, district]
}